package com.lex;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.lex.activitytext.R;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2016/6/30.
 */
public class TestRetrofitActivity extends AppCompatActivity {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        Retrofit retrofit = new Retrofit.Builder().baseUrl("http//www.kuaidi100.com/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        LogisticsService service = retrofit.create(LogisticsService.class);
        Call<LogisticsInfoResponse> callback = service.getLogisticsInfo("zhongtong", "405123024058");

        callback.enqueue(new Callback<LogisticsInfoResponse>() {
            @Override
            public void onResponse(Call<LogisticsInfoResponse> call, Response<LogisticsInfoResponse> response) {
                Log.d("LexLog", "call:" + call.toString());
                Log.d("LexLog", "response body:" + response.body().toString());
            }

            @Override
            public void onFailure(Call<LogisticsInfoResponse> call, Throwable t) {
                Log.d("LexLog", "请求错误");
            }
        });
    }
}
